package com.luck.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * 添加拦截器
 * Created by Hua wb on 2018/11/13.
 */
@Configuration
public class WebMvcConfig extends WebMvcConfigurationSupport {

    /**
     * 跳转页面
     * @param registry
     */
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/toLogin").setViewName("login");
        super.addViewControllers(registry);
    }

    /**
     * 拦截器
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // addPathPatterns 拦截规则 excludePathPatterns 排除拦截
        registry.addInterceptor(new LoginInterceptor()).addPathPatterns("/**")
                .excludePathPatterns("/toLogin", "/register.html","/css/**",
                        "/user/add", "/user/loginCheck", "/user/loginTourist","/user/userActivate/**"
                ,"/swagger-ui.html"
                ,"/statics/**","classpath:/statics/"
                ,"/swagger-ui.html","classpath:/META-INF/resources/"
                ,"/webjars/**", "classpath:/META-INF/resources/webjars/");
        super.addInterceptors(registry);
        /*registry.addResourceHandler("/statics/**").addResourceLocations("classpath:/statics/");
        // 解决 SWAGGER 404报错
        registry.addResourceHandler("/swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");*/
    }
}
